From 2ab1c0a3d88c47442842f0cb62705921b07dcf5c Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 25 Apr 2009 19:40:41 +0000 Subject: [PATCH] Follow-up r49880, tweaks to Special:CreatePage: * Fix doc, use @ingroup, NOT @addtogroup * Allow to use the subpage paramter if the "target" URL parameter is not passed * Fixed a fatal error when calling Special:CreatePage?target=> (GET request with invalid target) * Escaping messages used for Skin::makeLinkObj() since they won't be escaped by that function * Fixed double escaping for 'createpage-submitbutton' * Whitespaces tweaks --- includes/specials/SpecialCreatePage.php | 48 ++++++++++++------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/includes/specials/SpecialCreatePage.php b/includes/specials/SpecialCreatePage.php index 63dcf3e012..ba0ce4152b 100644 --- a/includes/specials/SpecialCreatePage.php +++ b/includes/specials/SpecialCreatePage.php @@ -1,4 +1,5 @@ for the Uniwiki extension CreatePage * Originally licensed as: GNU GPL v2.0 or later * @@ -12,16 +13,15 @@ * @author Evan Wheeler * @author Adam Mckaig (at UNICEF) * @author Siebrand Mazeland (integrated into MediaWiki core) - * @addtogroup SpecialPage + * @ingroup SpecialPage */ - class SpecialCreatePage extends SpecialPage { function __construct() { SpecialPage::SpecialPage( 'CreatePage', 'createpage' ); } - public function execute( $params ) { + public function execute( $par ) { global $wgOut, $wgRequest, $wgUser; $this->setHeaders(); @@ -31,37 +31,34 @@ class SpecialCreatePage extends SpecialPage { return; } - $wgOut->addWikiMsg( 'createpage-summary' ); + $this->outputHeader(); // check to see if we are trying to create a page - $target = $wgRequest->getVal ( 'target' ); - $title = Title::newFromText ( $target ); + $target = $wgRequest->getVal( 'target', $par ); + $title = Title::newFromText( $target ); // check for no title if ( $wgRequest->wasPosted() && $target === '' ) { $this->error( wfMsg( 'createpage-entertitle' ) ); - } - // check for invalid title - elseif ( $wgRequest->wasPosted() && is_null( $title ) ) { - $this->error( wfMsg( 'createpage-badtitle', $target ) ); - } - elseif ( $target != null ) { - if ( $title->getArticleID() > 0 ) { + } elseif ( $target !== '' ) { + if ( !$title instanceof Title ) { + // check for invalid title + $this->error( wfMsg( 'createpage-badtitle', $target ) ); + } else if ( $title->getArticleID() > 0 ) { // if the title exists then let the user know and give other options - $wgOut->addWikiText ( wfMsg ( 'createpage-titleexists', $title->getFullText() ) . "
" ); + $wgOut->addWikiMsg( 'createpage-titleexists', $title->getFullText() ); + $wgOut->addHTML( '
' ); $skin = $wgUser->getSkin(); - $editlink = $skin->makeLinkObj( $title, wfMsg ( 'createpage-editexisting' ), 'action=edit' ); - $thisPage = Title::newFromText ( 'CreatePage', NS_SPECIAL ); - $wgOut->addHTML ( $editlink . '
' - . $skin->makeLinkObj ( $thisPage, wfMsg ( 'createpage-tryagain' ) ) - ); + $editlink = $skin->makeLinkObj( $title, wfMsgHTML( 'createpage-editexisting' ), 'action=edit' ); + $thislink = $skin->makeLinkObj( $this->getTitle(), wfMsgHTML( 'createpage-tryagain' ) ); + $wgOut->addHTML( $editlink . '
' . $editlink ); return; } else { /* TODO - may want to search for closely named pages and give * other options here... */ // otherwise, redirect them to the edit page for their title - $wgOut->redirect ( $title->getEditURL() ); + $wgOut->redirect( $title->getEditURL() ); } } @@ -79,16 +76,17 @@ class SpecialCreatePage extends SpecialPage { } // output the form - $form = Xml::openElement( 'fieldset' ) . + $wgOut->addHTML( + Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'createpage' ) ) . # This should really use a different message wfMsgWikiHtml( 'createpage-instructions' ) . - Xml::openElement( 'form', array( 'method' => 'post', 'name' => 'createpageform', 'action' => '' ) ) . + Xml::openElement( 'form', array( 'method' => 'post', 'name' => 'createpageform', 'action' => $this->getTitle()->getLocalUrl() ) ) . Xml::element( 'input', array( 'type' => 'text', 'name' => 'target', 'size' => 50, 'value' => $newTitle ) ) . '
' . - Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'createpage-submitbutton' ) ) ) . + Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'createpage-submitbutton' ) ) ) . Xml::closeElement( 'form' ) . - Xml::closeElement( 'fieldset' ); - $wgOut->addHTML( $form ); + Xml::closeElement( 'fieldset' ) + ); } /* * Function to output an error message -- 2.20.1